#include<bitsdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10,mod=1e9+7;
int n,m,h[N];
ll f[N]; 


int main(){
	while(scanf("%d%d",&n,&m)!=EOF){
		priority_queue<pair<int,int> > q;
		memset(f,0,sizeof(f));
		for(int i=1;i<=n;i++){
			scanf("%d",&h[i]);
			int x=h[i]%3;
			if(h[i]%3==0) f[0]=(f[0]+h[i]/3)%mod;
			else f[0]=(f[0]+h[i]/3+1)%mod;
			q.push(make_pair(x,h[i]));
		}
//		printf("%lld\n",f[0]);
		int cnt=0;
		while(q.size()&&cnt<m){
			int x=q.top().first,y=q.top().second;
			q.pop();
			cnt++;
			if(x==2||x==1){
				y=y-2;
				x=y%3;
				f[cnt]=(f[cnt-1]-1+mod)%mod;
				if(y<=0) continue;
				q.push(make_pair(x,y));
			}
			else{
				y=y-2;
				x=y%3;
				f[cnt]=f[cnt-1];
				q.push(make_pair(x,y));
			}
		}
		ll ans=0;
		for(int i=0;i<=m;i++) ans=(ans+f[i])%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
